// pages/index2/index2.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pid:'',
    arrName:'',
    checks1: [
    ],
    checks: [
     
    ],
    TypeId:'',//选中的经营id
    TypeName: '',//选中的经营id
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.setData({
      checks1:[
        { name: options.name, value: options.pid, checked: true },
      ],
      pid: options.pid,
      arrName: options.name
    })
    app.post("/category/merchant_type","get",{id:that.data.pid}).then(res =>{
      res.forEach(function(v,i){
        res[i].checked = false;
        res[i].value = res[i].id;
      })
      that.setData({ checks:res})
    })
  },
  

  //主营分类1
  clicks: function (e) {
    let that = this;
    let index = e.currentTarget.dataset.index;
    let arrs = that.data.checks;
    
    if (arrs[index].checked == false) {
      for (var s = 0; s < arrs.length; s++) {
        arrs[s].checked = false;
      }
      arrs[index].checked = true;
      that.setData({ TypeId: arrs[index].id, TypeName: arrs[index].name })
    } else {
      arrs[index].checked = false;
    }
    that.setData({
      checks: arrs,
    })
    
  },
  showModal(error) {
    wx.showModal({
      content: error,
      showCancel: false,
    })
  },
  goactive:function(){
    let that = this;
    
    if(!that.data.TypeId){
      that.showModal("请选择经营分类");
      return;
    }
    
     wx.navigateTo({
       url: '../index3/index3?pid=' + that.data.pid + "&TypeId=" + that.data.TypeId + "&TypeName=" + that.data.TypeName+"&arrname="+that.data.arrName,
     })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})